package com.lingxinst.farm.app

import android.app.Application
import android.content.Context
import com.lynn.common.net.HttpUtils
import com.lynn.common.net.listener.IGetAppInfo
import com.lynn.common.utils.LoggerUtil
import com.lynn.common.utils.spf.LocalCacheUtil
import com.therouter.TheRouter

//import dagger.hilt.android.HiltAndroidApp

/**
 * @description:
 * @author: bailing
 * @datetime: 2025/5/28 11:38
 **/
//@HiltAndroidApp
class FarmApp : Application() {
    companion object {
        private var mAppContext: Context? = null

        fun getAppContext(): Context {
            if (mAppContext != null) {
                return mAppContext!!
            } else {
                throw RuntimeException("The global environment variable \"context\" is null.")
            }

        }
    }

    override fun onCreate() {
        super.onCreate()
        mAppContext = applicationContext
        initUtils()
//        LocaleHelper.updateOnAppStart(this)
    }

    private fun initUtils() {
        // 初始化本地存储工具类
        LocalCacheUtil.init(this)
        // 初始化网络请求工具类
        HttpUtils.init(object : IGetAppInfo{
            override fun getAppVersionName(): String {
                return BuildConfig.VERSION_NAME
            }

            override fun getAppVersionCode(): String {
                return BuildConfig.VERSION_CODE.toString()
            }

            override fun isDebug(): Boolean {
                return BuildConfig.DEBUG
            }

            override fun getApplicationContext(): Context {
                return applicationContext
            }

        })
        // 初始化日志打印工具类
        LoggerUtil.init(BuildConfig.DEBUG)
    }

    /**
     * 是Context的方法，用于在创建Context 对象时对其进行定制化设置
     * 主要用于在应用启动时做一些全局的初始化工作
     */
    override fun attachBaseContext(base: Context?) {
        TheRouter.isDebug = BuildConfig.DEBUG
        super.attachBaseContext(base)
    }

}